package com.gitee.tianchaohongyu.example.api;

import com.gitee.tianchaohongyu.example.dao.UserDao;
import com.gitee.tianchaohongyu.example.entity.User;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * 用户接口
 */
@AllArgsConstructor
@RestController
@RequestMapping
public class UserApi {

    private UserDao userDao;

    @GetMapping("/{id}")
    public String get(@PathVariable Long id) {
        User one = userDao.getOne(id);
        return one.getName();
    }

    @GetMapping("/save")
    public User save() {
        User user = new User();
        user.setName(LocalDateTime.now().toString());
        return userDao.save(user);
    }
}
